package com.hankol.newretail.adapter

import android.content.Context
import android.os.Bundle
import android.view.View
import android.widget.ImageView
import android.widget.TextView
import com.baselibrary.Constants
import com.baselibrary.extension.checkNotNull
import com.baselibrary.extension.checkValue
import com.baselibrary.router.ActivityRouter
import com.baselibrary.utils.*
import com.baselibrary.view.mediascontentview.MediaLayout
import com.baselibrary.view.PhotosContentView
import com.baselibrary.view.PhotosContentViewAdapter
import com.bumptech.glide.Glide
import com.bumptech.glide.load.MultiTransformation
import com.bumptech.glide.load.resource.bitmap.CenterCrop
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.RequestOptions
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.BaseViewHolder
import com.hankol.newretail.R
import com.hankol.newretail.bean.EvaluationBean
import com.hankol.newretail.widget.EvaluationRatingBar
import java.util.*
import kotlin.collections.ArrayList

/**
 * @author: 关忆北、
 * @date: 2022/8/8
 * @Des：已评价列表
 */
class HaveEvaluateListAdapter : BaseQuickAdapter<EvaluationBean, BaseViewHolder>(R.layout.item_have_evaluate_list) {

    override fun convert(helper: BaseViewHolder, item: EvaluationBean) {
        helper.setText(R.id.tv_order_store_name, item.shopName.checkValue())
        helper.getView<TextView>(R.id.tv_order_store_name).setOnClickListener {//进入酒窖详情
            val hashMap = HashMap<String, Any>()
            hashMap["id"] = "${item.shopId}"
            hashMap["dealerCode"] = "${item.dealerCode}"
            ARouterUtils.jump(ActivityRouter.WINE_CELLAR.WINCE_CELLAR_DETAIL, hashMap)
        }
        helper.setText(R.id.tv_evaluate_date, TimeUtil.fromToday(item.commentTime))
        GlideUtils.loadImg_228(mContext, item.skuCover, helper.getView(R.id.round_order_cover))
        helper.setText(R.id.tv_order_title, item.spuName.checkValue())
        val ratingBar = helper.getView<EvaluationRatingBar>(R.id.erb_rating_level)
        ratingBar.setStarStyle(12, true, ScreenUtils.dpToPx(2).toFloat(), 4, 12)
        ratingBar.setRatingLevel(item.commentResult, true)
        helper.setText(R.id.tv_evaluation_content, item.commentContent.checkValue())
        val nineGridPhoto = helper.getView<MediaLayout>(R.id.photo_content_view)
        if (item.mediaInfoList.checkNotNull()) {
            nineGridPhoto.visibility = View.VISIBLE
            var urlList = ArrayList<String>()
            var typeList = ArrayList<Int>()
            for (media in item.mediaInfoList) {
                typeList.add(media.type)
                if (media.type == 1) {
                    urlList.add(media.videoUrl)
                } else {
                    urlList.add(media.coverUrl)
                }
            }
            nineGridPhoto.setImageUrls(urlList, typeList)
            nineGridPhoto.spacing = ScreenUtils.dpToPx(5).toFloat()
            nineGridPhoto.setCallback { position -> //图片详情
                val bundle = Bundle()
                bundle.putStringArrayList(Constants.KEY_URLS, urlList)
                bundle.putInt(Constants.KEY_INDEX, position)
                bundle.putStringArrayList(Constants.KEY_COMMENT_CONTENT, arrayListOf(item.commentContent))
                bundle.putStringArrayList(Constants.KEY_COMMENT_TITLE, arrayListOf())
                ActivityRouter.startActivity(ActivityRouter.WINE_CELLAR.IMG_VIDEO_DETAIL, bundle)
            }
        } else {
            nineGridPhoto.visibility = View.GONE
        }
    }
}

